package gui.win.genotree;

import core.utils.Utils;
import gui.Segl1;
import gui.processor.Processor;
import gui.processor.Worker;
import gui.utils.Para;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Buttons extends JPanel implements ActionListener{
    private JButton close;
    private JButton draw;
    private Genotree gtree;
    private Segl1 segL1;
    public Buttons(Segl1 L1_RpgsGui, Genotree gtree){
        super(new BorderLayout());
        this.segL1 = L1_RpgsGui;
        this.gtree = gtree;
        this.add(Utils.getButton(close = new JButton("CANCEL"), 184, 22, new Color(102, 102, 102), new Color(178, 178, 178), this, "CANCEL"), BorderLayout.WEST);
        this.add(Utils.getButton(draw = new JButton("DRAW"), 184, 22, new Color(102, 102, 102), new Color(178, 178, 178), this, "CREATE TREE"), BorderLayout.EAST);
    }

    public void actionPerformed(ActionEvent evt) {
        Object source = evt.getSource();
        if(source == close){gtree.closeFrame();}
        else if(source == draw){
            if(gtree.getPath().equals("") || gtree.getPath()==null){JOptionPane.showMessageDialog(null, "Path to templates not entered.", "alert", JOptionPane.ERROR_MESSAGE);}
            else if(!new File(gtree.getPath()).exists()){JOptionPane.showMessageDialog(null, "Alignment file does not exist.", "alert", JOptionPane.ERROR_MESSAGE);}
            else{
                Para.EXTALNPATH = gtree.getPath();
                Processor processor = new Processor(segL1);
                processor.setTask(Para.TASK_EXT_TREE);
                Worker sl = new Worker(processor);
                sl.execute();
                gtree.closeFrame();
            }
        }
    }
}